package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.lianzhihui.romeex.bean.ProfitFindHomeBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.mvp.model.base
 * @ClassName: InvitationModellmp
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/11/9 18:18
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/9 18:18
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class HuaZhuanModelImp {


    private Context context;
    HuaZhuanModelInterface model;

    public HuaZhuanModelImp(Context context, HuaZhuanModelInterface model) {
        this.context = context;
        this.model = model;
    }

    /**
     * 划转首页
     *
     * @param coinNameCobo
     * @param coinName
     */
    public void requestFindHome(String coinNameCobo, String coinName) {
        HttpParams params = new HttpParams();
        params.put("coinNameCobo", coinNameCobo);
        params.put("coinName", coinName);
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                if (o.getCode() == 200 && o.getData() != null) {
                    ProfitFindHomeBean bean = GsonUtil.GsonToBean(o.getData(), ProfitFindHomeBean.class);
                    model.responseFindHomeSuccess(bean);
                } else {
                    model.onFailure();
                }
            }

            @Override
            public void onError(ApiException e) {
                model.onFailure();
            }
        }).post(APIConstant.PROFIT_FINDHOME, params);
    }

    /**
     * 划转
     *
     * @param coinNameCobo
     * @param coinName
     */
    public void requestTransfer(String coinNameCobo, String coinName, String amount, String transferType) {
        HttpParams params = new HttpParams();
        params.put("coinNameCobo", coinNameCobo);
        params.put("coinName", coinName);
        params.put("amount", amount);
        params.put("transferType", transferType);
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                if (o.getCode() == 200 && o.getData() != null) {
//                    ProfitFindHomeBean bean = GsonUtil.GsonToBean(o.getData(), ProfitFindHomeBean.class);
                    model.responseTransSuccess();
                } else {
                    model.onFailure();
                }
            }

            @Override
            public void onError(ApiException e) {
                if (e.getMessage() != null && !e.getMessage().isEmpty()) {
                    ToastUtils.showShort(e.getMessage());
                }
                model.onFailure();
            }
        }).post(APIConstant.PROFIT_TRANSFER, params);
    }


}
